﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using WooCoo.Data;

namespace WooCoo.ObjectModel
{
    /// <summary>
    /// Repository模式接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <remarks>由于事务具有较强的上下文关系，在实体Repsitory接口中不涉及事务提交，需要配合事务上下文进行</remarks>
    public interface IRepository : IUnitOfWork
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        IQueryable AsQueryable();
        /// <summary>
        /// 根据主键值，查询实体，需要注意本框架目前只支持采用单主键式。
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        object Find(params object[] keys);
        /// <summary>
        /// 添加实体对象到数据上下文
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Add(object entity);

        /// <summary>
        /// 从数据上下文中删除实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="searchCondition"></param>
        /// <returns></returns>
        int Remove(object entity);

        /// <summary>
        /// 实体更新至数据上下文
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Update(object entity);
        /// <summary>
        /// 数据更新，自动根据实体状态
        /// </summary>
        /// <param name="entityOrList"></param>
        /// <returns></returns>
        int SaveChanges(object entityOrList);
    }
}
